package com.smart.lib.controller;

import com.smart.lib.service.EchartsService;
import com.smart.lib.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 数据可视化API接口层
 * */
@RestController
@CrossOrigin
@RequestMapping("/echart")
public class EchartsController {
    @Autowired
    EchartsService echartsService;

    /**
     * 查询大分类及其所有子分类的图书总数
     * */
    @RequestMapping(value = "/getCategoryPieData", method = RequestMethod.GET, produces = "application/json; utf-8")
    public Response getCategoryPieData(){
        return echartsService.selectParentCategoryWithChildrenBookCount();
    }

    /**
     * 本周每日借阅和归还统计
     * */
    @RequestMapping(value = "/getWeekBorrowData", method = RequestMethod.GET, produces = "application/json; utf-8")
    public Response getWeekBorrowData(){
        return echartsService.selectCurrentWeekData();
    }

    /**
     * 本月每日借阅和归还统计
     * */
    @RequestMapping(value = "/getMonthBorrowData", method = RequestMethod.GET, produces = "application/json; utf-8")
    public Response getMonthBorrowData(){
        return echartsService.selectCurrentMonthData();
    }

    /**
     * 本年每日借阅和归还统计
     * */
    @RequestMapping(value = "/getYearBorrowData", method = RequestMethod.GET, produces = "application/json; utf-8")
    public Response getYearBorrowData(){
        return echartsService.selectCurrentYearData();
    }

    /**
     * 热门图书借阅排行
     * */
    @RequestMapping(value = "/getTop5BorrowedBooks", method = RequestMethod.GET, produces = "application/json; utf-8")
    public Response getTop5BorrowedBooks(){
        return echartsService.selectTop5BorrowedBooks();
    }
}
